﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;

public partial class adminstrator_editStudent : System.Web.UI.Page

{
    public OleDbConnection myConnection;
    public static readonly string sConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sConnectionString);
        myConnection.Open();//打开数据库连接
        if (Session["UserName"] == null && Session["UserNo"] == null)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时(或未登录),请您重新登录！');parent.location.href='../login.aspx'</script>", false);
        if (!IsPostBack)//是否第一次打开
        {
            string detID = Request.QueryString["deleteID"];//获取页面传递的ID号
            if(detID !=null)
            {
            GridView1.PageIndex=int.Parse(Request.QueryString["pIndex"]);
          delete(detID);//调用删除函数
            }
        }

    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        string stuID = GridView1.DataKeys[e.NewEditIndex][0].ToString();
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", ",script type='text/javascript'>location.href='editStudentStart.aspx?stuID=" + stuID + " ';</script>", false);

    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "", ",script type='text/javascript'>" +
                  "if(confirm('确定删除学生学籍？')){location.href='editStudent.aspx?deleteID=" + GridView1.DataKeys[e.RowIndex][1].ToString() + " &pIndex" + GridView1);
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex=e.NewPageIndex;
      bind(Session["sDL"].ToString(),Session["sTB"].ToString());
    }
protected void ButtonResrt_Click(object sender, EventArgs e)
{
    DropDownList1.SelectedIndex=0;
    TextBox1.Text="";
    Label1.Text="";
    GridView1.DataSource=null;
    GridView1.DataBind();
}
protected void ButtonOK_Click(object sender, EventArgs e)
{
    if(TextBox1.Text!="")//输入查询信息不为空
    {
    Session["sDL"]="";
        Session["sTB"]=TextBox1.Text.Trim();//存储查询内容
        if(DropDownList1.SelectedIndex==0)
        Session["sDL"]="sNo";//将查询字段设置为学号
        else if(DropDownList1.SelectedIndex==1)
            Session["sDL"]="sName";//将查询字段设置为姓名
        else if(DropDownList1.SelectedIndex==2)
            Session["sDL"]="sColllege";
        bind(Session["sDL"].ToString(),Session["sTB"].ToString());
        
    }
}
}